import sys, pygame, time, random, os, traceback
import pymunk
sys.path.append(os.path.abspath( os.path.dirname(sys.argv[0])+'/jplur/' ) )

from jplur import *




jplur.brain = Brain()
jplur.brain.setup()


#pygame.mixer.music.load(os.path.dirname(sys.argv[0])+'/simple.mp3')
#pygame.mixer.music.play(-1)

oldtime = time.time()





print pygame.display.get_surface()

running = 1
while running:
	try:
		for event in pygame.event.get():
			print event.type
			if event.type == 2: 
				print event
				jplur.brain.handle_keydown(event.key)
			if event.type == 3: 

				jplur.brain.handle_keyup(event.key)
			if event.type == pygame.MOUSEBUTTONDOWN:
				jplur.brain.handle_mousedown( event.pos )
			if event.type == pygame.QUIT: 
				running = 0
				sys.exit()
				
		ztime = oldtime - time.time()

		if abs(ztime) > 1.0/60.0:
		
			jplur.brain.update()	
			pygame.display.flip()
			oldtime = time.time()
			
		
	except:
		print traceback.print_exc(file=sys.stdout)

